home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14530 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.perl.misc,comp.lang.c
  4. Subject: Re: PROGRAMERS OF ANY LANGUAGE
  5. Date: 15 Apr 1996 09:16:17 -0700
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4ktsohINNmt@keats.ugrad.cs.ubc.ca>
  8. References: <Pine.SOL.3.91.960329010021.13209A-100000@harvey> <4krg5h$7tt@nntp1.best.com> <4krrccINN78i@keats.ugrad.cs.ubc.ca> <4ksfaq$jug@nntp1.best.com>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <4ksfaq$jug@nntp1.best.com>, Zenin  <zenin@best.com> wrote:
  12.  >Kazimir Kylheku <c2a192@ugrad.cs.ubc.ca> wrote:
  13.  >    >snip<
  14.  >: Actually I do program much. I wouldn't talk if I were you, read on...
  15.  >    Hmm, didn't see my simily did you?  Oh well...
  16.  >    >snip<
  17.  >: In your if statement, the else clause gets executed if *any one* of the
  18.  >: test expressions fails! ``if (1 && 1 && 0)'' will launch into the *else* clause.
  19.  >: In MY if statement, the else clause only gets executed it the *outermost* test
  20.  >: condition fails. ``if (1) if (1) if (0) statement 1; else statement2;'' will
  21.  >: cause *neither* statement1 *nor* statement2 to be executed!
  22.  >    There are ways around this as well, however simply taking the 10
  23.  >    secs of time to add the }{s as your past example did would be the
  24.  >    easyest way in Perl.
  25.  >
  26.  >: See, the two are not equivalent at all!
  27.  >    You're right, and that teaches me to followup after a double
  28.  >    espresso. ;-}
  29.  
  30. Same with me: a dangling else in C is taken to be the innermost case, not the
  31. outermost. In LR parser lingo, it is resolved by doing a shift, not a reduce,
  32. which causes the innermost else clause to be ``stacked'' with the nearest
  33. matching if. This is the most common resolution of the ambiguity. The yacc
  34. parser generator reflects this thinking---in the case of a shift/reduce
  35. ambiguity in the grammar, it emits a warning, and generates a parser that will
  36. do the shift.
  37.  
  38. Thus my bracketing of the original C program was as incorrect as your attempt
  39. to make an equivalent single if using the and operator. 
  40.  
  41. Make that two double espressos.
  42. -- 
  43. I'm not really a jerk, but I play one on Usenet.
  44.